﻿using Microsoft.AspNetCore.Razor.Language.Intermediate;
using System;
using System.Collections.Generic;
using System.Text;

namespace Common.Utility
{
    public static class DataHelp
    {
        /// <summary>
        /// 不能为null，转换错误返回0
        /// </summary>
        /// <param name="s"></param>
        /// <returns></returns>
        public static int ToInt(this string s)
        {
            if (string.IsNullOrWhiteSpace(s)) return 0;
            int i;
            if (int.TryParse(s, out i)) return i;
            return 0;
        }
        public static string ToString(this object s)
        {
            try
            {
                return s.ToString();
            }
            catch (Exception)
            {
                return string.Empty;
            }
        }
    }
}
